package com.atguigu.yygh.cmn.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.atguigu.yygh.cmn.mapper.CmnMapper;
import com.atguigu.yygh.model.cmn.Dict;
import com.atguigu.yygh.vo.cmn.DictEeVo;
import org.springframework.beans.BeanUtils;

/**
 * @author ybl
 * @version 1.9
 * @date 2021/5/14 20:15
 * excel 导入功能读文件时的监听器
 */
// 导入功能
public class DictListener extends AnalysisEventListener<DictEeVo> {

  private CmnMapper cmnMapper;

  // 注入cmnmapper
  public DictListener(CmnMapper cmnMapper) {
    this.cmnMapper = cmnMapper;
  }

  @Override
  public void invoke(DictEeVo dictEeVo, AnalysisContext analysisContext) {
    Dict dict = new Dict();
    BeanUtils.copyProperties(dictEeVo,dict);
    cmnMapper.insert(dict);
  }

  @Override
  public void doAfterAllAnalysed(AnalysisContext analysisContext) {

  }
}
